# -*- coding:utf-8 -*-
class Solution:
    def InversePairs(self, data):
        # write code here
        self.num = 0
        self.helper(data)
        return self.num
    def helper(self, data):
        if not data or len(data) == 1:
            return data
        left = self.helper(data[:len(data)//2])
        right = self.helper(data[len(data)//2:])
        res = []
        l = len(left)-1
        r = len(right)-1
        while l >= 0 and r >= 0:
            if left[l] > right[r]:
                self.num += r+1
                res.insert(0, left[l])
                l -= 1

            else:
                res.insert(0, right[r])
                r -= 1

        if l >= 0:
            res = left[:l+1] + res
        if r >= 0:
            res = right[:r+1] + res
        return res
test = Solution()
print(test.InversePairs([7,5,6,4]))